package com.example.springboot.mapper;

import com.example.springboot.entity.students;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 个人信息管理Mapper接口
 *
 * @author bxd
 * @date 2024-06-15
 */
@Mapper
public interface StudentMapper {

    @Select("SELECT\n" +
            "\ts.*,\n" +
            "\tu.user_id,\n" +
            "\tu.email,\n" + // 假设 user 表中有一个 email 字段
            "\tu.username\n" + // 假设 user 表中有一个 username 字段
            "FROM\n" +
            "\tstudents s\n" +
            "INNER JOIN\n" +
            "\tusers u\n" +
            "ON \n" +
            "\ts.student_id = u.user_id")
    List<students> findAll();

    @Delete("DELETE FROM students WHERE student_id=#{student_id}")
    void deleteStu(int student_id);

    @Insert("INSERT INTO students (student_id, name, dob, gender, phone, address, resume, education, experience, skills) " +
            "VALUES (#{students.student_id}, #{students.name}, #{students.dob}, #{students.gender}, " +
            "#{students.phone}, #{students.address}, #{students.resume}, #{students.education}, " +
            "#{students.experience}, #{students.skills})")
    void addStudent(students student);

    @Update("UPDATE students " +
            "SET name=#{name}, dob=#{dob}, gender=#{gender}, phone=#{phone}, " +
            "address=#{address}, resume=#{resume}, education=#{education}, " +
            "experience=#{experience}, skills=#{skills} " +
            "WHERE student_id=#{student_id}")
    void updateStudent(students student);

    @Select("SELECT * from students where user_id=#{user_id} ")
    List<students> selectByStudentId(Integer user_id);

    @Select("SELECT * from students s " +
            "INNER JOIN users u ON s.student_id = u.user_id " +
            "where s.name=#{name}")
    List<students> selectByName(String name);
}